package com.example.a14110100420.yuejian.WActivity.personal;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WAdapter.personal.MyGuanzhuListAdapter;
import com.example.a14110100420.yuejian.WSerivice.PersonalService;
import com.example.a14110100420.yuejian.Wbase.BaseActivity;
import com.example.a14110100420.yuejian.Wbase.Conast;
import com.example.a14110100420.yuejian.Wbean.personal.MyConcern;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class GuanzhuDetailActivity extends AppCompatActivity {
    final String userid = BaseActivity.getUserid();
    private RecyclerView recyclerView;
    private RecyclerView.Adapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guanzhu_detail);
        getSupportActionBar().hide();

        guanzhuDetail();

    }
    private void guanzhuDetail(){
        recyclerView = (RecyclerView) findViewById(R.id.my_focus);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Conast.base_Url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        PersonalService service = retrofit.create(PersonalService.class);
        Call<List<MyConcern>> call = service.focusById(userid);
        call.enqueue(new Callback<List<MyConcern>>() {
            @Override
            public void onResponse(Call<List<MyConcern>> call, Response<List<MyConcern>> response) {
                List<MyConcern> concern =  response.body();
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(GuanzhuDetailActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                adapter = new MyGuanzhuListAdapter(GuanzhuDetailActivity.this,concern);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());

            }

            @Override
            public void onFailure(Call<List<MyConcern>> call, Throwable t) {
                Toast.makeText(GuanzhuDetailActivity.this,"失败",Toast.LENGTH_SHORT).show();

            }
        });


    }

    @Override
    protected void onResume() {
        super.onResume();
        guanzhuDetail();
    }
}
